package com.winning.common.xmlSchema;

import org.dom4j.Document;
import org.dom4j.Element;

import java.util.Iterator;

/**
 * 类名称：SchemaSummary
 * 类描述：schema校验结果错误描述类
 * 创建人：liuwensheng
 * 创建时间：2017-1-12 上午11:09:54
 * 修改人：liuwensheng
 * 修改时间：2017-1-12 上午11:09:54
 * 修改备注：
 */
public class SchemaSummary {
    private int errorCount = 0;
    private int warnCount = 0;
    private int infoCount = 0;

    public int getInfoCount() {
        return infoCount;
    }

    public int getErrorCount() {
        return this.errorCount;
    }

    public int getWarnCount() {
        return warnCount;
    }

    public void fromSchemaResultDocument(Document document) {

        System.out.println("xml:" + document.asXML());

        Element root = document.getRootElement();
        Iterator<Element> it = root.elementIterator();
        while (it.hasNext()) {
            Element el = it.next();
            if ("error".equalsIgnoreCase(el.getName())) {
                errorCount += 1;
            } else if ("warn".equalsIgnoreCase(el.getName())) {
                warnCount += 1;
            } else {
                infoCount += 1;
            }
        }
    }

}
